package net.cityside.summer.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.cityside.summer.domain.GalleryImg;
import net.cityside.summer.serivce.IGalleryImgService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("gallery")
public class GalleryController {

	@Autowired
	private IGalleryImgService galleryImgService;

	@RequestMapping
	public ModelAndView home() {
		ModelAndView mv = new ModelAndView("gallery");
		return mv;
	}

	@RequestMapping("imglist")
	public @ResponseBody
	List<Map<String, Object>> homeImageList() {
		List<GalleryImg> imgs = galleryImgService.listLatestN(10);
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(
				imgs.size());
		for (GalleryImg img : imgs) {
			Map<String, Object> item = new HashMap<String, Object>(2);
			item.put("title", img.getTitle());
			item.put("filename", img.getFilename());
			list.add(item);
		}
		return list;
	}

}
